﻿using Framework.Serializer;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Framework.Serializer
{
    class ProtoBufSerializer : BytesSerializeBase
    {
        public override byte[] Serialize(object obj)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                ProtoBuf.Serializer.NonGeneric.Serialize(ms, obj);
                return ms.ToArray();
            }
        }

        public override T DeSerialize<T>(byte[] source)
        {
            using (MemoryStream ms = new MemoryStream(source, false))
            {
                return ProtoBuf.Serializer.Deserialize<T>(ms);
            }
        }
    }
}
